package ai4games_tests.soccer;

import game2dai.maths.Vector2D;

public class GoalKeeper extends PlayerBase implements Constants {

	Vector2D rearInterposeTarget = new Vector2D();
	
	public GoalKeeper(String name, Vector2D position, double radius,
			Vector2D velocity, double max_speed, Vector2D heading, double mass,
			double max_turn_rate, double max_force, int side, Team team, int playerNumber) {
		
		super(name, position, radius, velocity, max_speed, heading, mass,
				max_turn_rate, max_force, side, team, playerNumber);
		FSM().setGlobalState(KeeperGlobal.state());
	}
	
	public boolean isBallWithinRange(){
		return Vector2D.distSq(pos, team.pitch.ball.pos()) <= KeeperInBallRangeSq;
	}

	public boolean isBallWithinInterceptRange(){
		return Vector2D.distSq(team.getOwnGoalCenter(), team.pitch.ball.pos()) <= GoalKeeperInterceptRangeSq;
	}

	public boolean tooFarFromGoalMouth(){
		return Vector2D.distSq(pos, getRearInterposeTarget()) > GoalKeeperInterceptRangeSq;
	}

	public Vector2D getRearInterposeTarget(){
		double x = team.goal.centre.x;
		double y = (PITCH_WIDTH - GOAL_WIDTH)/2 + (team.pitch.ball.pos().y * GOAL_WIDTH / PITCH_WIDTH);
		rearInterposeTarget.set(x,y);
		return rearInterposeTarget;
	}
	
	public boolean isGoalKeeper(){
		return true;
	}
	
	public boolean isFieldPlayer(){
		return false;
	}


}
